﻿using SqlSugar;

namespace Magic.Core;
/// <summary>
/// SqlSugar仓储类
/// </summary>
public class SugarRepository<T>:SimpleClient<T> where T : class,new()
{
    /// <summary>
    /// 构造函数
    /// </summary>
    public SugarRepository()
    {
        //多库自动切换仓储
        var iTenant=SugarContext.Instance.GetConnectionScopeWithAttr<T>();
        base.Context = iTenant;
    }
    #region 仓储事务
    /// <summary>
    /// 所有db
    /// </summary>
    public void BeginTran()
    {
        Context.AsTenant().BeginTran();
    }
    /// <summary>
    /// 所有db
    /// </summary>
    public void CommitTran()
    {
        Context.AsTenant().CommitTran();
    }
    /// <summary>
    /// 所有db
    /// </summary>
    public void RollbackTran()
    {
        Context.AsTenant().RollbackTran();
    }
    #endregion
}